﻿package kit4j.view.cs.swing.dialog;

import java.awt.Component;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;

import kit4j.common.command.Command;
import kit4j.view.cs.FontSize;
import kit4j.view.cs.FontStyle;
import kit4j.view.cs.SimpleCharset;
import kit4j.view.cs.exception.ListItemNotFoundException;
import kit4j.view.cs.exception.ListNoSelectionException;
import kit4j.view.cs.swing.component.JFontList;
import kit4j.view.cs.swing.component.JFontSizeList;
import kit4j.view.cs.swing.component.JFontStyleList;
import kit4j.view.cs.swing.component.JSimpleCharsetComboBox;
import kit4j.view.cs.swing.listener.ExecuteCommandListSelectionListener;
import kit4j.view.cs.swing.listener.ShowListSelectionListener;

/**
 * JFontChooserDialog为用户选择系统字体提供了一种简单的机制。<br />
 * 以下显示一个JFontChooserDialog，其初始显示选择字体"宋体-Plain-14",然后将用户选择的字体信息打印出来:
 * 
 * <pre>
 * <code>
 *  JFontChooserDialog fc = new JFontChooserDialog(ownerFrame, "字体");
 *  fc.setSelectedFont(new Font("宋体", Font.PLAIN, 14)); 
 *  if(fc.showChooseDialog() == JOptionPane.OK_OPTION) { 
 * 		System.out.println(fc.getSelectedFont()); 
 *  }
 * </code>
 * </pre>
 * 
 * 警告：该类型不是线程安全的。
 * 
 * @author MiniKnife
 * 
 */
public class JFontChooser extends JDialog {

	private static final long serialVersionUID = 1L;

	/**
	 * 用户选项类型。JOptionPane.OK_OPTION、JOptionPane.CANCEL_OPTION、JOptionPane. CLOSED_OPTION 之一。
	 */
	private int optionType;

	/**
	 * 面板组件显示字体。控制面板中的非示例面板的组件的显示字体。
	 */
	private Font componentFont;

	/**
	 * 用户当前选择的字体类型。
	 */
	private Font selectedFont;

	/**
	 * 用户当前选择的字体类型的持有锁。所有需要使用selectedFont对象的代码都需要持有该锁。
	 */
	private Object selectedFontLockObj = new Object();

	/**
	 * 字体名称列表标签。
	 */
	private JLabel fontNameLabel;

	/**
	 * 字体风格列表标签。
	 */
	private JLabel fontStyleLabel;

	/**
	 * 字体尺寸列表标签。
	 */
	private JLabel fontSizeLabel;

	/**
	 * 字体示例字符集标签。
	 */
	private JLabel fontExampleCharsetLabel;

	/**
	 * 当前选择的字体名称显示域。
	 */
	private JTextField fontNameField;

	/**
	 * 当前选择的字体风格显示域。
	 */
	private JTextField fontStyleField;

	/**
	 * 当前选择的字体尺寸显示域。
	 */
	private JTextField fontSizeField;

	/**
	 * 字体名称列表。
	 */
	private JFontList fontNameList;

	/**
	 * 字体风格列表。
	 */
	private JFontStyleList fontStyleList;

	/**
	 * 字体尺寸列表。
	 */
	private JFontSizeList fontSizeList;

	/**
	 * 字体名称列表面板。
	 */
	private JScrollPane fontNameListPane;

	/**
	 * 字体风格列表面板。
	 */
	private JScrollPane fontStyleListPane;

	/**
	 * 字体尺寸列表面板。
	 */
	private JScrollPane fontSizeListPane;

	/**
	 * 字体示例显示面板。
	 */
	private JPanel fontExamplePane;

	/**
	 * 字体示例字符显示域。
	 */
	private JLabel fontExampleText;

	/**
	 * 字体示例字符集选项列表。
	 */
	private JSimpleCharsetComboBox fontExampleCharsetList;

	/**
	 * 字体示例字符集。
	 */
	private List<SimpleCharset> charsetList;

	/**
	 * 确认提交按钮。
	 */
	private JButton submitBtn;

	/**
	 * 取消按钮。
	 */
	private JButton cancelBtn;

	public JFontChooser() {
		super();
		init();
	}

	public JFontChooser(Frame owner) {
		super(owner);
		init();
	}

	public JFontChooser(Dialog owner) {
		super(owner);
		init();
	}

	public JFontChooser(Window owner) {
		super(owner);
		init();
	}

	public JFontChooser(Frame owner, String title) {
		super(owner, title);
		init();
	}

	public JFontChooser(Dialog owner, String title) {
		super(owner, title);
		init();
	}

	public JFontChooser(Window owner, ModalityType modalityType) {
		super(owner, modalityType);
		init();
	}

	public JFontChooser(Window owner, String title) {
		super(owner, title);
		init();
	}

	public JFontChooser(Window owner, String title, ModalityType modalityType) {
		super(owner, title, modalityType);
		init();
	}

	public JFontChooser(Frame owner, String title, GraphicsConfiguration gc) {
		super(owner, title, true, gc);
		init();
	}

	public JFontChooser(Dialog owner, String title, GraphicsConfiguration gc) {
		super(owner, title, true, gc);
		init();
	}

	public JFontChooser(Window owner, String title, ModalityType modalityType, GraphicsConfiguration gc) {
		super(owner, title, modalityType, gc);
		init();
	}

	/**
	 * 初始化对话框。
	 */
	public void init() {
		initDialog();
		createComponent();
		initListener();
		initComponent();
		initLayout();
	}

	/**
	 * 初始化对话框自身属性。
	 */
	private void initDialog() {
		if (this.getOwner() != null) {
			this.setIconImages(this.getOwner().getIconImages());
		}
		this.setIconImage(null);
		this.setSize(500, 350);
		this.setModal(true);
		this.setContentPane(new JPanel() {

			private static final long serialVersionUID = 1L;

			@Override
			public Insets getInsets() {
				return new Insets(5, 5, 5, 5);
			}
		});
		this.componentFont = getDefaultFont();
	}

	/**
	 * 构建对话框中包含的所有组件。
	 */
	private void createComponent() {
		this.optionType = JOptionPane.NO_OPTION;

		this.fontNameLabel = createLabel("字体(F):");
		this.fontStyleLabel = createLabel("样式(Y):");
		this.fontSizeLabel = createLabel("大小(S):");
		this.fontExampleCharsetLabel = createLabel("示例字符集(R):");
		this.fontExampleText = createLabel(null);

		this.fontNameField = createTextField(25);
		this.fontStyleField = createTextField(20);
		this.fontSizeField = createTextField(10);

		this.fontNameList = createFontList();
		this.fontStyleList = createStyleList();
		this.fontSizeList = createSizeList();

		this.fontNameListPane = createScrollPane(fontNameList);
		this.fontStyleListPane = createScrollPane(fontStyleList);
		this.fontSizeListPane = createScrollPane(fontSizeList);

		this.fontExamplePane = createExamplePane("示例");

		this.fontExampleCharsetList = createSubCharsetComboBox();

		this.charsetList = this.<SimpleCharset> createList();

		this.submitBtn = createButton("确定");
		this.cancelBtn = createButton("取消");
	}

	/**
	 * 初始化对话框中包含的所有组件的属性值。
	 */
	private void initComponent() {
		charsetList.addAll(Arrays.<SimpleCharset> asList(new SimpleCharset("中文", "中华人民共和国"), new SimpleCharset("英文字母",
				"aAbBcCdDxXyYzZ"), new SimpleCharset("数字", "0123456789"), new SimpleCharset("数学符号", "≠≧∑∮㏒％℃㎏∷√"),
				new SimpleCharset("特殊符号", "★※♀♂№▓")));
		fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		fontExampleText.setHorizontalAlignment(SwingConstants.CENTER);
		fontExamplePane.setLayout(new GridLayout(1, 1));
		fontExamplePane.add(new JScrollPane(fontExampleText));

		initFont(componentFont);
	}

	/**
	 * 初始化对话框显示的各个组件的字体。
	 */
	private void initFont(Font font) {
		this.fontNameLabel.setFont(font);
		this.fontStyleLabel.setFont(font);
		this.fontSizeLabel.setFont(font);
		this.fontExampleCharsetLabel.setFont(font);

		this.fontSizeList.setFont(font);

		this.submitBtn.setFont(font);
		this.cancelBtn.setFont(font);
	}

	/**
	 * 初始化对话框中所有可视组件的布局。
	 */
	private void initLayout() {
		GridBagLayout gb = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();

		this.setLayout(gb);

		gbc.insets = new Insets(1, 5, 1, 1);

		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontNameLabel, gbc);

		gbc.gridx = 1;
		gbc.gridy = 0;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontStyleLabel, gbc);

		gbc.gridx = 2;
		gbc.gridy = 0;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontSizeLabel, gbc);

		gbc.gridx = 0;
		gbc.gridy = 1;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontNameField, gbc);

		gbc.gridx = 1;
		gbc.gridy = 1;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontStyleField, gbc);

		gbc.gridx = 2;
		gbc.gridy = 1;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontSizeField, gbc);

		gbc.gridx = 3;
		gbc.gridy = 1;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(submitBtn, gbc);

		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0.55;
		gbc.weighty = 0.5;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontNameListPane, gbc);

		gbc.gridx = 1;
		gbc.gridy = 2;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0.35;
		gbc.weighty = 0.5;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontStyleListPane, gbc);

		gbc.gridx = 2;
		gbc.gridy = 2;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0.1;
		gbc.weighty = 0.5;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontSizeListPane, gbc);

		gbc.gridx = 3;
		gbc.gridy = 2;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.NORTHWEST;
		this.add(cancelBtn, gbc);

		gbc.gridx = 0;
		gbc.gridy = 3;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontExampleCharsetLabel, gbc);

		gbc.gridx = 1;
		gbc.gridy = 3;
		gbc.gridwidth = 2;
		gbc.gridheight = 2;
		gbc.weightx = 0;
		gbc.weighty = 0.5;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.anchor = GridBagConstraints.WEST;
		this.add(fontExamplePane, gbc);

		gbc.gridx = 0;
		gbc.gridy = 4;
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
		gbc.weightx = 0;
		gbc.weighty = 0;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.anchor = GridBagConstraints.NORTHWEST;
		this.add(fontExampleCharsetList, gbc);
	}

	/**
	 * 初始化对话框中所有组件的事件监听器。
	 */
	private void initListener() {
		// 字体属性变化命令
		Command fontPropertyChangeCmd = new Command() {
			public void execute() {
				try {
					synchronized (selectedFontLockObj) {
						selectedFont = generateSelectedFont();
						fontExampleText.setFont(selectedFont);
					}
				} catch (ListNoSelectionException e1) {
					return;
				}
			}
		};

		// 字体变化命令
		Command fontChangeCmd = new Command() {
			public void execute() {
				List<SimpleCharset> charsetList = new ArrayList<SimpleCharset>();
				int most = 0, temp;
				SimpleCharset targetCharset = null;

				synchronized (selectedFontLockObj) {
					for (SimpleCharset charset : charsetList) {
						temp = selectedFont.canDisplayUpTo(charset.getCharSequence().toString());

						// 如果该字体能部分或全部显示字符集，则添加该字符集到候选列表
						if (temp != 0) {
							charsetList.add(charset);

							/*
							 * 如果(most == 0)或者(temp > 0 && most > 0 && temp > most)或者(temp == -1 && most !=
							 * -1)，则该字体对当前字符集的支持数量比之前支持数量最高的要高
							 */
							if ((most == 0) || (temp > 0 && most > 0 && temp > most) || (temp == -1 && most != -1)) {
								targetCharset = charset;
								most = temp;
							}
						}
					}
				}

				try {
					fontExampleCharsetList.setItems(charsetList.toArray(new SimpleCharset[0]));

					if (charsetList.isEmpty()) {
						fontExampleText.setText(null);
					} else {
						fontExampleCharsetList.setSelectedItem(targetCharset);
					}
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				}
			}
		};

		// 添加字体变化监听器
		ExecuteCommandListSelectionListener fontChangeListener = new ExecuteCommandListSelectionListener();
		fontChangeListener.addCommand(fontPropertyChangeCmd);
		fontChangeListener.addCommand(fontChangeCmd);

		fontNameList.addListSelectionListener(fontChangeListener);

		// 添加字体属性变化监听器
		ExecuteCommandListSelectionListener fontPropertyChangeListener = new ExecuteCommandListSelectionListener();
		fontPropertyChangeListener.addCommand(fontPropertyChangeCmd);

		fontStyleList.addListSelectionListener(fontPropertyChangeListener);
		fontSizeList.addListSelectionListener(fontPropertyChangeListener);

		// 添加列表选项名称变化监听器
		fontNameList.addListSelectionListener(new ShowListSelectionListener(fontNameField));
		fontStyleList.addListSelectionListener(new ShowListSelectionListener(fontStyleField));
		fontSizeList.addListSelectionListener(new ShowListSelectionListener(fontSizeField));

		// 添加字符集变化监听器
		fontExampleCharsetList.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				if (ItemEvent.SELECTED == e.getStateChange()) {
					try {
						fontExampleText.setText(fontExampleCharsetList.getSelectedSimpleCharset().getCharSequence()
								.toString());
					} catch (ListNoSelectionException e1) {
						e1.printStackTrace();
					}
				}
			}
		});

		// 添加确定、取消、关闭选项监听器
		submitBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JFontChooser.this.submitChoose(JOptionPane.OK_OPTION);
			}
		});
		cancelBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				JFontChooser.this.submitChoose(JOptionPane.CANCEL_OPTION);
			}
		});
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent evt) {
				JFontChooser.this.submitChoose(JOptionPane.CLOSED_OPTION);
			}
		});
	}

	/**
	 * 初始化字体列表的选择。
	 */
	private void initSelect() {
		synchronized (selectedFontLockObj) {
			if (selectedFont == null) {
				return;
			}
		}

		try {
			Font font = getSelectedFont();

			fontNameList.setSelectedFont(font, true);
			fontStyleList.setSelectedFontStyleByValue(font.getStyle(), true);
			fontSizeList.setSelectedFontSizeByValue(font.getSize(), true);
		} catch (ListItemNotFoundException e) {
			e.printStackTrace();
		} catch (ListNoSelectionException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据指定的字符串创建一个简单的标签。
	 * 
	 * @param text
	 *            标签要显示的字符。
	 * @return 显示指定字符串的标签。
	 */
	private JLabel createLabel(String text) {
		return new JLabel(text);
	}

	/**
	 * 根据指定的长度创建一个简单的文本域。
	 * 
	 * @param size
	 *            文本域尺寸。
	 * @return 具有指定尺寸的文本域。
	 */
	private JTextField createTextField(int size) {
		return new JTextField(size);
	}

	/**
	 * 创建一个简单的字体列表。
	 * 
	 * @return 列表。
	 */
	private JFontList createFontList() {
		return new JFontList();
	}

	/**
	 * 创建一个简单的字体风格列表。
	 * 
	 * @return 列表。
	 */
	private JFontStyleList createStyleList() {
		return new JFontStyleList();
	}

	/**
	 * 创建一个简单的字体尺寸列表。
	 * 
	 * @return 列表。
	 */
	private JFontSizeList createSizeList() {
		return new JFontSizeList();
	}

	/**
	 * 创建一个具有指定组件的视图的滚动面板。
	 * 
	 * @param view
	 *            显示的组件
	 * @return 具有指定组件的视图的滚动面板
	 */
	private JScrollPane createScrollPane(Component view) {
		return new JScrollPane(view);
	}

	/**
	 * 创建一个具有指定标题的TitleBorder的面板。
	 * 
	 * @param title
	 *            标题
	 * @return 指定标题的TitleBorder的面板
	 */
	private JPanel createExamplePane(String title) {
		JPanel jp = new JPanel();
		TitledBorder border = new TitledBorder(title);
		border.setTitleFont(getDefaultFont());
		jp.setBorder(border);

		return jp;
	}

	/**
	 * 创建一个简单的下拉列表组件。
	 * 
	 * @return
	 */
	private JSimpleCharsetComboBox createSubCharsetComboBox() {
		return new JSimpleCharsetComboBox();
	}

	/**
	 * 根据指定的字符串创建一个按钮。
	 * 
	 * @param text
	 *            字符串
	 * @return 一个显示指定字符串的按钮
	 */
	private JButton createButton(String text) {
		return new JButton(text);
	}

	/**
	 * 创建一个空的List（java.util.List）。
	 * 
	 * @return 一个空的List
	 */
	private <T> List<T> createList() {
		return new ArrayList<T>();
	}

	/**
	 * 获取默认的对话框显示字体。
	 * 
	 * @return 默认显示字体
	 */
	private Font getDefaultFont() {
		Font f = Font.decode("微软雅黑-12");
		if (f == null) {
			f = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
		}

		return f;
	}

	/**
	 * 根据列表中的选择生成具有指定属性的字体。
	 * 
	 * @return 字体
	 * @throws ListNoSelectionException
	 *             当有列表项未选择值时，抛出此异常。
	 */
	private Font generateSelectedFont() throws ListNoSelectionException {
		Font font = fontNameList.getSelectedFont();
		FontStyle fontStyle = fontStyleList.getSelectedFontStyle();
		FontSize fontSize = fontSizeList.getSelectedFontSize();

		return font.deriveFont(fontStyle.getValue(), (float) fontSize.getValue());
	}

	/**
	 * 提交用户选项类型。
	 * 
	 * @param option
	 */
	private void submitChoose(int option) {
		this.optionType = option;
		this.setVisible(false);
		this.dispose();
	}

	/**
	 * 设置对话框的字体。
	 * 
	 * @param font
	 *            要设置的字体
	 * @see JDialog#setFont(Font)
	 */
	public void setDialogFont(Font font) {
		super.setFont(font);
	}

	/**
	 * 返回对话框的字体。
	 * 
	 * @return 对话框的字体
	 * @see JDialog#getFont()
	 */
	public Font getDialogFont() {
		return super.getFont();
	}

	/**
	 * 设置对话框的组件的字体。 注意：对话框中除字体示例面板外的所有组件均使用同类字体。
	 * 
	 * @param font
	 *            要设置的字体
	 */
	public void setComponentFont(Font font) {
		this.componentFont = font;
		initFont(componentFont);
	}

	/**
	 * 返回对话框的组件的字体。
	 * 
	 * @return 对话框的组件的字体
	 */
	public Font getComponentFont() {
		return this.componentFont;
	}

	/**
	 * 获取选择的字体。
	 * 
	 * @return 用户选择的字体
	 * @throws ListNoSelectionException
	 *             如果当前没有选择一个字体，抛出此异常。
	 */
	public Font getSelectedFont() throws ListNoSelectionException {
		synchronized (selectedFontLockObj) {
			if (selectedFont == null) {
				throw new ListNoSelectionException();
			}

			return selectedFont;
		}
	}

	/**
	 * 选择指定的字体。
	 * 
	 * @param f
	 *            要选择的字体
	 */
	public void setSelectedFont(Font f) {
		synchronized (selectedFontLockObj) {
			this.selectedFont = f;
		}
		initSelect();
	}

	/**
	 * 显示一个字体选择对话框。
	 * 
	 * @return 用户选项类型。值为以下之一:
	 *         <ul>
	 *         <li>JOptionPane.CANCEL_OPTION</li>
	 *         <li>JOptionPane.OK_OPTION</li>
	 *         <li>JOptionPane.CLOSED_OPTION</li>
	 *         </ul>
	 */
	public int showChooseDialog() {
		optionType = JOptionPane.CLOSED_OPTION;

		if (this.getOwner() != null) {
			this.setLocationRelativeTo(this.getOwner());
		}
		this.setVisible(true);

		return optionType;
	}

	/**
	 * 返回字体列表中字体对象的数组。
	 * 
	 * @return 字体对象的数组
	 * @see JFontList#getListFonts()
	 */
	public Font[] getFonts() {
		return fontNameList.getListFonts();
	}

	/**
	 * 设置字体列表中的字体对象数组。
	 * 
	 * @param fonts
	 *            要设置的字体对象数组
	 * @see JFontList#setListFonts(Font[])
	 */
	public void setFonts(Font[] fonts) {
		fontNameList.setListFonts(fonts);
	}

	/**
	 * 返回字体风格列表中字体风格对象的数组。
	 * 
	 * @return 字体风格对象的数组
	 * @see JFontStyleList#getListFonts()
	 */
	public FontStyle[] getFontStyles() {
		return fontStyleList.getListFontStyles();
	}

	/**
	 * 设置字体风格列表中的字体风格对象数组。
	 * 
	 * @param fontStyles
	 *            要设置的字体风格对象数组
	 * @see JFontStyleList#setListFonts(Font[])
	 */
	public void setFontStyles(FontStyle[] fontStyles) {
		fontStyleList.setListFontStyles(fontStyles);
	}

	/**
	 * 返回字体尺寸列表中字体尺寸对象的数组。
	 * 
	 * @return 字体尺寸对象的数组
	 * @see JFontSizeList#getListFonts()
	 */
	public FontSize[] getFontSizes() {
		return fontSizeList.getListFontSizes();
	}

	/**
	 * 设置字体尺寸尺寸列表中的字体尺寸对象数组。
	 * 
	 * @param fontSizes
	 *            要设置的字体尺寸对象数组
	 * @see JFontSizeList#setListFontSizes(Font[])
	 */
	public void setFontSizes(FontSize[] fontSizes) {
		fontSizeList.setListFontSizes(fontSizes);
	}

	public JLabel getFontNameLabel() {
		return fontNameLabel;
	}

	public void setFontNameLabel(JLabel fontNameLabel) {
		this.fontNameLabel = fontNameLabel;
	}

	public JLabel getFontStyleLabel() {
		return fontStyleLabel;
	}

	public void setFontStyleLabel(JLabel fontStyleLabel) {
		this.fontStyleLabel = fontStyleLabel;
	}

	public JLabel getFontSizeLabel() {
		return fontSizeLabel;
	}

	public void setFontSizeLabel(JLabel fontSizeLabel) {
		this.fontSizeLabel = fontSizeLabel;
	}

	public JLabel getFontExampleCharsetLabel() {
		return fontExampleCharsetLabel;
	}

	public void setFontExampleCharsetLabel(JLabel fontExampleCharsetLabel) {
		this.fontExampleCharsetLabel = fontExampleCharsetLabel;
	}

	public JTextField getFontNameField() {
		return fontNameField;
	}

	public void setFontNameField(JTextField fontNameField) {
		this.fontNameField = fontNameField;
	}

	public JTextField getFontStyleField() {
		return fontStyleField;
	}

	public void setFontStyleField(JTextField fontStyleField) {
		this.fontStyleField = fontStyleField;
	}

	public JTextField getFontSizeField() {
		return fontSizeField;
	}

	public void setFontSizeField(JTextField fontSizeField) {
		this.fontSizeField = fontSizeField;
	}

	public JFontList getFontNameList() {
		return fontNameList;
	}

	public void setFontNameList(JFontList fontNameList) {
		this.fontNameList = fontNameList;
	}

	public JFontStyleList getFontStyleList() {
		return fontStyleList;
	}

	public void setFontStyleList(JFontStyleList fontStyleList) {
		this.fontStyleList = fontStyleList;
	}

	public JFontSizeList getFontSizeList() {
		return fontSizeList;
	}

	public void setFontSizeList(JFontSizeList fontSizeList) {
		this.fontSizeList = fontSizeList;
	}

	public JScrollPane getFontNameListPane() {
		return fontNameListPane;
	}

	public void setFontNameListPane(JScrollPane fontNameListPane) {
		this.fontNameListPane = fontNameListPane;
	}

	public JScrollPane getFontStyleListPane() {
		return fontStyleListPane;
	}

	public void setFontStyleListPane(JScrollPane fontStyleListPane) {
		this.fontStyleListPane = fontStyleListPane;
	}

	public JScrollPane getFontSizeListPane() {
		return fontSizeListPane;
	}

	public void setFontSizeListPane(JScrollPane fontSizeListPane) {
		this.fontSizeListPane = fontSizeListPane;
	}

	public JPanel getFontExamplePane() {
		return fontExamplePane;
	}

	public void setFontExamplePane(JPanel fontExamplePane) {
		this.fontExamplePane = fontExamplePane;
	}

	public JLabel getFontExampleText() {
		return fontExampleText;
	}

	public void setFontExampleText(JLabel fontExampleText) {
		this.fontExampleText = fontExampleText;
	}

	public JSimpleCharsetComboBox getFontExampleCharsetList() {
		return fontExampleCharsetList;
	}

	public void setFontExampleCharsetList(JSimpleCharsetComboBox fontExampleCharsetList) {
		this.fontExampleCharsetList = fontExampleCharsetList;
	}

	public List<SimpleCharset> getCharsetList() {
		return charsetList;
	}

	public void setCharsetList(List<SimpleCharset> charsetList) {
		this.charsetList = charsetList;
	}

	public JButton getSubmitBtn() {
		return submitBtn;
	}

	public void setSubmitBtn(JButton submitBtn) {
		this.submitBtn = submitBtn;
	}

	public JButton getCancelBtn() {
		return cancelBtn;
	}

	public void setCancelBtn(JButton cancelBtn) {
		this.cancelBtn = cancelBtn;
	}

	public static class Test {
		public static void main(String[] args) {
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					JFontChooser fc = new JFontChooser(new JDialog(), "字体");
					fc.setSelectedFont(new Font("宋体", Font.PLAIN, 14));
					if (fc.showChooseDialog() == JOptionPane.OK_OPTION) {
						try {
							System.out.println(fc.getSelectedFont());
						} catch (ListNoSelectionException e) {
							e.printStackTrace();
						}
					}
					// JFontChooserDialog fc = new JFontChooserDialog(
					// new JDialog(), "字体");
					// if (fc.showChooseDialog() == JOptionPane.OK_OPTION) {
					// try {
					// System.out.println(fc.getSelectedFont());
					// } catch (ListNoSelectionException e) {
					// e.printStackTrace();
					// }
					// }
					// fc.setSelectedFont(new Font("楷体", Font.BOLD +
					// Font.ITALIC,
					// 28));
					// if (fc.showChooseDialog() == JOptionPane.OK_OPTION) {
					// try {
					// System.out.println(fc.getSelectedFont());
					// } catch (ListNoSelectionException e) {
					// e.printStackTrace();
					// }
					// }
				}
			});
		}
	}

}
